using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ASP_TF2LogParser.UserControls
{
    public partial class PlayerWeaponStatsByLogId : System.Web.UI.UserControl
    {

        //string _playerId;
        //LogParser.DA.PlayerModel _model;

        protected void Page_Load( object sender, EventArgs e )
        {

            string playerId = Request[ "PlayerId" ];


            string logIdList = string.Empty;

            int leagueId = Convert.ToInt32( Request[ "leagueId" ] );
            List<int> logList = LogParser.DA.LogFileModel.GetLogIdList( leagueId );

            foreach ( int logId in logList )
            {
                if ( logIdList != string.Empty )
                    logIdList += ",";

                logIdList += logId.ToString();
            }

            if ( logIdList != string.Empty )
            {
                NoLeagueIdErrorMessage.Visible = false;
                WeaponStatsDataDivId.Visible = true;
                LoadPlayer( playerId, logIdList );
            }
            else
            {
                NoLeagueIdErrorMessage.Visible = true;
                WeaponStatsDataDivId.Visible = false;
            }

            
        }

        private void LoadPlayer( string playerId, string logIdList )
        {
            LogParser.DA.DataObjects.PlayerStatsDS.PlayerWeaponStatsSelectByPlayerIdDataTable dt = LogParser.DA.PlayerModel.GetPlayerWeaponStats( playerId, logIdList );
            playerWeaponStatsGridView.DataSource = dt;
            playerWeaponStatsGridView.DataBind();

        }

        public string GenerateUrl( string weaponName, string weaponId )
        {

            string returnUrl = "";

            returnUrl = "<a href='Weapon.aspx?weaponId=" + weaponId + "'>" + weaponName + "</a>";

            return returnUrl;


        }

        //#region Sorting

        //protected void weaponStats_Sorting( object sender, GridViewSortEventArgs e )
        //{
        //    DataTable dataTable = playerWeaponStatsGridView.DataSource as DataTable;

        //    if ( dataTable != null )
        //    {
        //        dataTable.DefaultView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql( GridViewSortDirection );
        //        playerWeaponStatsGridView.DataSource = dataTable;
        //        playerWeaponStatsGridView.DataBind();
        //    }



        //}

        //public SortDirection GridViewSortDirection
        //{
        //    get
        //    {
        //        if ( ViewState[ "sortDirection" ] == null )
        //            ViewState[ "sortDirection" ] = SortDirection.Ascending;

        //        SortDirection returnDirection = ( SortDirection ) ViewState[ "sortDirection" ];

        //        if ( ( SortDirection ) ViewState[ "sortDirection" ] == SortDirection.Ascending )
        //            ViewState[ "sortDirection" ] = SortDirection.Descending;
        //        else
        //            ViewState[ "sortDirection" ] = SortDirection.Ascending;



        //        return returnDirection;
        //    }
        //    set { ViewState[ "sortDirection" ] = value; }
        //}

        //private string ConvertSortDirectionToSql( SortDirection sortDirection )
        //{
        //    string newSortDirection = String.Empty;

        //    switch ( sortDirection )
        //    {
        //        case SortDirection.Ascending:
        //            newSortDirection = "ASC";
        //            break;

        //        case SortDirection.Descending:
        //            newSortDirection = "DESC";
        //            break;
        //    }

        //    return newSortDirection;
        //}

        //#endregion

    }





}